package make.money.gold;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class ListUtils {

    /**
     * 两集合的并集
     * @param list1
     * @param list2
     * @return
     */
    public static List<Integer> intersect(List<Integer> list1, List<Integer> list2){
        return list1.stream().filter(item->list2.contains(item)).collect(Collectors.toList());
    }

    /**
     * 去重并集
     *
     */
    public static List<Integer> unions(List<Integer> list1, List<Integer> list2){
        List<Integer> money = new ArrayList<>();
        money.addAll(list1);
        money.addAll(list2);

        return money.stream().distinct().collect(Collectors.toList());
    }

    /**
     * 获取对应集合中的数据
     * @param suijiResult
     * @param fileYun
     * @return
     */
    public static List<String> getSuijiYun(List<Integer> suijiResult,List<String> fileYun){
        suijiResult = suijiResult.stream().sorted().collect(Collectors.toList());
        if(suijiResult.get(suijiResult.size()-1)>fileYun.size()){return null;}
        List<String> suijiYun = new ArrayList<>();
        suijiResult.stream().forEach(data->suijiYun.add(fileYun.get(data)));
        return suijiYun;
    }


    public static void main(String[] args) {
        List<Integer> a= Arrays.asList(1);
        List<Integer> b= Arrays.asList(1);
        System.out.println(intersect(a,b).size());
    }
}
